package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.VersionControl;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * 版本控制convert
 * Created by wangjian7 on 2015/11/12.
 */
public class VersionControlConvert {
    public static DBObject castVersionCrotrolToDBObject(VersionControl versionCrotrol){
        DBObject dbo = new BasicDBObject();
        if (versionCrotrol.getId() != null) {
            dbo.put("_id", versionCrotrol.getId());
        }
        dbo.put("type", versionCrotrol.getType());
        dbo.put("updateTime", versionCrotrol.getUpdateTime());
        return dbo;
    }
    public static VersionControl castDBObjectToVersionCrotrol(DBObject dbObject){
        VersionControl versionCrotrol = new VersionControl();
        if(dbObject != null) {
            versionCrotrol.setId(ObjUtils.toLong(dbObject.get("_id")));
            versionCrotrol.setType(ObjUtils.toString(dbObject.get("type")));
            versionCrotrol.setUpdateTime(ObjUtils.toLong(dbObject.get("updateTime")));
        }else{
            return null;
        }
        return versionCrotrol;
    }
}
